import { Injectable } from '@angular/core';
import { Platform, ActionSheetController } from 'ionic-angular';
import * as Constant from '../../constant/constant';

@Injectable()
export class ActionSheetService {

  constructor(
    private platform: Platform,
    private actionSheetCtrl: ActionSheetController
  ) {}

  /*** 工作Action
   * */
  createCameraActionSheet(): Promise<any>  {
    return new Promise((resolve, reject)=>{
      const actionSheet = this.actionSheetCtrl.create({
        cssClass: 'office-camera-action',
        buttons: [
          {
            text: '拍照',
            icon: !this.platform.is('ios') ? 'camera' : null,
            handler: () => {
              resolve({
                type: Constant.CAMERA
              });
            }
          },
          {
            text: '从手机相册选择',
            icon: !this.platform.is('ios') ? 'image' : null,
            handler: () => {
              resolve({
                type: Constant.PHOTO
              });
            }
          },
          {
            text: '取消',
            role: 'cancel',
            icon: !this.platform.is('ios') ? 'close' : null,
            handler: () => {
              console.log('Cancel clicked');
            }
          }
        ]
      });

      actionSheet.present();
    })

  }

  /*** 身份证照片Action
   * */
  createIdentityCard(): Promise<any>  {
    return new Promise((resolve, reject)=>{
      const actionSheet = this.actionSheetCtrl.create({
        cssClass: 'office-camera-action',
        buttons: [
          {
            text: '查看大图',
            icon: !this.platform.is('ios') ? 'image' : null,
            handler: () => {
              resolve({
                type: Constant.LOOK
              });
            }
          },
          {
            text: '删除',
            role: 'destructive',
            icon: !this.platform.is('ios') ? 'trash' : null,
            handler: () => {
              resolve({
                type: Constant.RESET
              });
            }
          },
          {
            text: '取消',
            role: 'cancel',
            icon: !this.platform.is('ios') ? 'close' : null,
            handler: () => {
              console.log('Cancel clicked');
            }
          }
        ]
      });

      actionSheet.present();
    })

  }

}
